<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
		<script type="text/javascript" src="../internal.js"></script>
		<style type="text/css">
			.wrapper{width: 600px;padding: 10px;height:380px;overflow: hidden;border-bottom: 0px solid #d7d7d7;webkit-border-radius:0px 0px 5px 5px; -moz-border-radius:0px 0px 5px 5px; border-radius:0px 0px 5px 5px;}
			.localPath input{float: left;width: 350px;line-height: 20px;height: 27px;padding:0px;margin: 0px;overflow: hidden;}
			#clipboard{float:left;width: 140px;height: 30px;margin-left: 5px; overflow: hidden;}
			.description{ color: #0066cc; margin-top: 2px; width: 600px; height: 45px;float: left;line-height: 22px}
			#msg{ width: 95px; height: 30px; line-height:30px;float: left;color: #00a0e9;padding-left:5px;}
			#flashContainer{float: left;padding-top:5px;}
			#upload{float: left; width: 100%;height: 30px;margin:0px;cursor: pointer;text-align: center;padding-top:5px;}
		</style>
	</head>
	<body>
		<div class="wrapper">
			<div class="localPath">
				<input id="localPath" type="text" readonly />
				<div id="clipboard"></div>
				<div id="msg"></div>
			</div>
			<div id="flashContainer"></div>
			<div class="description">
				<span style="color: red"><var id="lang_resave"></var></span><var id="lang_step"></var>
			</div>
			<div id="upload" style="display: none;"><img id="uploadBtn"></div>
		</div>
		<script type="text/javascript" src="tangram.js"></script>
		<script type="text/javascript" src="wordimage.js"></script>
		<script type="text/javascript">
			editor.setOpt({
				wordImageFieldName: "upfile",
				compressSide: 0,
				maxImageSideLength: 900
			});
			var imageUrls = [],
				selectedImageCount = 0,
				optImageUrl = editor.getActionUrl(editor.getOpt('imageActionName')),
				optImageFieldName = editor.getOpt('imageFieldName'),
				optImageCompressBorder = editor.getOpt('imageCompressEnable') ? editor.getOpt('imageCompressBorder') : null,
				maxSize = editor.getOpt('imageMaxSize') * 1024 * 1024,
				extension = editor.getOpt('imageAllowFiles').join(';').replace(/\./g, '*.');
			var params = utils.serializeParam(editor.queryCommandValue('serverparam')) || '',
				urlWidthParams = optImageUrl + (optImageUrl.indexOf('?') == -1 ? '?' : '&') + params;
			utils.domReady(function () {
				var flashOptions = {
					container: "flashContainer",
					url: urlWidthParams,
					ext: editor.queryCommandValue('serverParam') || {},
					fileType: '{"description":"' + lang.fileType + '", "extension":"' + extension + '"}',
					flashUrl: 'imageUploader.swf',
					width: 600,
					height: 272,
					gridWidth: 120,
					gridHeight: 120,
					picWidth: 100,
					picHeight: 100,
					uploadDataFieldName: optImageFieldName,
					picDescFieldName: 'pictitle',
					maxSize: maxSize,
					compressSize: 1,
					maxNum: 32,
					compressSide: 0,
					compressLength: optImageCompressBorder
				};
				var callbacks = {
					selectFileCallback: function (selectFiles) {
						selectedImageCount += selectFiles.length;
						if (selectedImageCount)
							baidu.g("upload").style.display = "";
						dialog.buttons[0].setDisabled(true);
					},
					deleteFileCallback: function (delFiles) {
						selectedImageCount -= delFiles.length;
						if (!selectedImageCount) {
							baidu.g("upload").style.display = "none";
							dialog.buttons[0].setDisabled(false);
						}
					},
					uploadCompleteCallback: function (data) {
						try {
							var info = eval("(" + data.info + ")");
							info && imageUrls.push(info);
							selectedImageCount--;
							if (!imageUrls.length) {
								return false;
							}
							var urlPrefix = editor.getOpt('imageUrlPrefix'),
								images = domUtils.getElementsByTagName(editor.document, "img");
							editor.fireEvent('saveScene');
							for (var i = 0, img; img = images[i++]; ) {
								var src = img.getAttribute("word_img");
								if (!src) {
									continue;
								}
								for (var j = 0, url; url = imageUrls[j++]; ) {
									if (src.indexOf(url.title.replace(" ", "")) != -1) {
										img.src = urlPrefix + url.url;
										img.setAttribute("_src", urlPrefix + url.url);
										img.setAttribute("title", url.title);
										domUtils.removeAttributes(img, ["word_img", "style", "width", "height"]);
										editor.fireEvent("selectionchange");
										break;
									}
								}
							}
							editor.fireEvent('saveScene');
							hideFlash();
							dialog.close(false);
						} catch (e) {
						}
					},
					uploadErrorCallback: function (data) {
						console && console.log(data);
					},
					allCompleteCallback: function () {
						dialog.buttons[0].setDisabled(false);
					}
				};
				wordImage.init(flashOptions, callbacks);
			});
		</script>
	</body>
</html>